import { MarkList,FileParams } from '@/utils/knowledge';
import { Effect, ImmerReducer, Reducer, Subscription } from 'umi';
import {getfile, getMark, Toupdate} from '../services/index'
export interface IndexModelState {
  marklist:MarkList[],
  updateResult:{},
  fileList:FileParams[],
  fileSum:number
}
export interface IndexModelType {
  namespace: 'knowledge';
  state: IndexModelState;
  effects: {
    getMark: Effect;
    Toupdate: Effect;
    getFiles: Effect;
  };
  reducers: {
    save: Reducer<IndexModelState>;
  }
}

const IndexModel: IndexModelType = {
  namespace: 'knowledge',
  state: {
    marklist:[],
    updateResult:{},
    fileList:[],
    fileSum:0
  },
  effects: {
    *getMark({ payload,type }, { call, put }) {
        let result = yield call(getMark,100,200)
        // console.log(result,type,'result===')
        yield put({
          type:'save',
          payload:{
            marklist:result.data[0]
          }
        })
    },
    *Toupdate({payload,type},{call,put}){
      // console.log(payload,'payload')
      let result = yield call(Toupdate,payload.id,payload.status)
      // console.log(result,'result')
      yield put({
        type:'save',
        payload:{
          updateResult:result
        }
      })
    },
    *getFiles({payload,type},{call,put}){
      // console.log(payload,'page....')
      let result = yield call(getfile,payload.page)
      // console.log('result...',result)
      yield put({
        type:'save',
        payload:{
          fileList:result.data[0],
          fileSum:result.data[1]
        }
      })
    }
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  }
};

export default IndexModel;